interface objectType {
  [propName: string]: any;
}
// 深度拷贝;不能拷贝函数
function deepClone(originObject: objectType): objectType {
  const type = Object.prototype.toString.call(originObject)
  switch (type) {
    case "[object Object]":
      const clone = {
      }
      const keys = Object.getOwnPropertyNames(originObject)
      keys.forEach(key => {
        const originType = typeof originObject[key]
        do {
          if (originType === "object") {
            clone[key] = deepClone(originObject[key])
            break
          }
          clone[key] = originObject[key]
        } while (false);

      })
      return clone

    case "[object Array]":
      const copyArray = []
      originObject.forEach((item, index) => {
        const originType = typeof item
        do {
          if (originType === "object") {
            copyArray[index] = deepClone(item)
            break;
          }
          copyArray[index] = item
        } while (false);
      })
      return copyArray
    default:
      break;
  }
}

// const obj = {
//   name: "zs",
//   age: "20",
//   address: {
//     province: "重庆市",
//     city: '重庆市',
//     obj: {
//       province: "重庆市",

//     }
//   }
// }
const obj: any[] = [{
  name: "zs",
  age: "20",
  address: {
    province: "重庆市",
    city: '重庆市',
    obj: {
      province: "重庆市",
    }
  }
}, 2, 3, 45]

const res = deepClone(obj)
obj[0].address.province = '四川省'
console.log(obj, res);
